package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import dao.UtilisateurDAO;

/**
 * Servlet implementation class SupprimerUser
 */
@WebServlet("/SupprimerUser")
public class DeleteUser extends HttpServlet {
	private static final long serialVersionUID = 1L;
	public static final String VUE = "/WEB-INF/listUser.jsp";
	public static final String VUE_INDEX = "/WEB-INF/connectionUser.jsp";
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeleteUser() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
	    /* Récupération de la session depuis la requête */
	    HttpSession session = request.getSession();
	    
	    if(session.getAttribute("admin")!=null){
		
	    	//on recuperere l'identifiant de l'utilisateur
			String idUser = request.getParameter("idUser");
			int idU = Integer.parseInt(idUser);
			UtilisateurDAO uDAO = new UtilisateurDAO();
			uDAO.deleteUser(idU);
	    	
	    	this.getServletContext().getRequestDispatcher(VUE).forward(request, response);
	    }else{
	    	this.getServletContext().getRequestDispatcher(VUE_INDEX).forward(request, response);
	    }
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
